package com.whmall.service.crm.module.invoice.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.whmall.component.util.NumberUtils;
import com.whmall.service.crm.entity.dto.invoice.SubstituteInvoiceCompanyAddReqDTO;
import com.whmall.service.crm.entity.dto.invoice.SubstituteInvoiceCompanyUpdateReqDTO;
import org.springframework.stereotype.Component;

@Component
public class SubstituteInvoiceCompanyValidator {

    public void validate(SubstituteInvoiceCompanyAddReqDTO reqDTO) {

        if (reqDTO == null){
            throw new IllegalArgumentException("请求参数异常");
        }

        if (reqDTO.getCompanyId() == null){
            throw new IllegalArgumentException("公司id不能为空");
        }

        if (StrUtil.isEmpty(reqDTO.getCompanyAbbr())){
            throw new IllegalArgumentException("公司简称不能为空");
        }

        if (CollUtil.isEmpty(reqDTO.getSubstituteUseRange())){
            throw new IllegalArgumentException("代开使用范围不能为空");
        }

        if (reqDTO.getSubstitutePoint() == null){
            throw new IllegalArgumentException("代开点数不能为空");
        }

        if (!NumberUtils.check(reqDTO.getSubstitutePoint(), 2)){
            throw new IllegalArgumentException("代开点数只能传两位小数");
        }

        if (reqDTO.getUserId() == null){
            throw new IllegalArgumentException("代开用户不能为空");
        }

    }

    public void validateUpdate(SubstituteInvoiceCompanyUpdateReqDTO reqDTO) {

        if (reqDTO == null){
            throw new IllegalArgumentException("请求参数异常");
        }

        if (reqDTO.getId() == null){
            throw new IllegalArgumentException("代开公司id不能为空");
        }

        if (StrUtil.isEmpty(reqDTO.getCompanyAbbr())){
            throw new IllegalArgumentException("公司简称不能为空");
        }

        if (CollUtil.isEmpty(reqDTO.getSubstituteUseRange())){
            throw new IllegalArgumentException("使用范围不能为空");
        }

        if (reqDTO.getSubstitutePoint() == null){
            throw new IllegalArgumentException("代开点数不能为空");
        }

        if (!NumberUtils.check(reqDTO.getSubstitutePoint(), 2)){
            throw new IllegalArgumentException("代开点数只能传两位小数");
        }

        if (reqDTO.getUserId() == null){
            throw new IllegalArgumentException("代开用户不能为空");
        }

    }

}
